fix(cmd): preserve user-supplied base-url in ucloud init#146
Merged
Conversation
init unconditionally reset ConfigIns.BaseURL to DefaultBaseURL right before persisting, discarding the custom base-url entered at the prompt. The value only took effect during remote validation and the confirmation line echoed the overwritten default, so users could not tell their input was dropped. Dedicated-cloud customers pointing at a non-primary gateway had to work around it via `ucloud config update --base-url`. Remove the overwrite; ConfigBaseURL() already leaves BaseURL populated (the package-level default when the user just presses Enter). Timeout, MaxRetryTimes and Active still reset to their defaults since init has no prompt for them. Add TestInitPersistsUserSuppliedBaseURL, which drives the real NewCmdInit().Run() against a fake gateway and asserts the reloaded profile keeps the entered base-url.
|
🔴 平台 PR 默认硬拦,需管理员 Approve 放行(或由管理员提交)。判定:改动触及平台/受保护路径(cmd/configure.go, cmd/configure_test.go) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
缺陷
ucloud init交互中用户输入的自定义 base-url 无法落盘。NewCmdInit在持久化前无条件执行platform.ConfigIns.BaseURL = platform.DefaultBaseURL,把用户输入覆盖回主站默认值:fetchRegionWithConfig)生效;DefaultBaseURL;专属云客户(需指向
https://api.ucloud-global.com/等非主站网关)走ucloud init拿不到可用 profile,只能改用ucloud config update --base-url ...绕过。修复
删除那行无条件覆盖即可。
ConfigBaseURL()已保证BaseURL非空——用户直接回车时ConfigIns仍保持包级默认值DefaultBaseURL,故删除后默认路径行为不变。同一段的
Timeout/MaxRetryTimes/Active保持原样重置:这三项在 init 流程中本就没有用户输入环节,属于合理的初始化,只有BaseURL在 prompt 处有用户输入,故只改它。测试
新增
TestInitPersistsUserSuppliedBaseURL:驱动真实的NewCmdInit().Run()(stdin 喂入公钥/私钥/自定义 base-url/日志选项,配合假网关),重新读盘断言落盘的 base-url 与用户输入一致,同时校验 timeout/max-retry/active 仍为各自默认值(避免过度约束)。已验证把缺陷行放回后该用例变红、且仅 base-url 断言失败。验证
/opt/homebrew/bin/go build ./...通过go vet ./cmd/...无输出go test ./...全部包 ok,既有 init/config 用例无回归